<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">网站设置 <small>所有网站设置</small></h3>
            <?php echo breadcrumb(array('网站设置', 'advert/grid'=>'广告管理')); ?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-search"></i>搜索</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal form-search" action="<?php echo base_url('advert/grid') ?>" method="get">
                        <div class="row-fluid">
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">标题</label>
                                    <div class="controls">
                                        <input type="text" name="title" value="<?php echo @$title?>" placeholder="标题" class="m-wrap medium">
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">所属广告位</label>
                                    <div class="controls">
                                        <select name="position" class="medium m-wrap valid">
                                            <option value="">请选择广告位</option>
                                            <?php foreach ($advertArray as $key=>$value) : ?>
                                                <option value="<?php echo $key;?>" <?php if ($key == $this->input->get('position')): ?>selected="selected"<?php endif?>><?php echo $value; ?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="span4">
                                <div class="control-group">
                                    <label class="control-label">状态</label>
                                    <div class="controls">
                                        <select name="status" class="m-wrap medium">
                                            <option value="">请选择</option>
                                            <?php foreach (array('1'=>'上架', '0'=>'下架') as $key=>$value) :?>
                                            <option value="<?php echo $key;?>" <?php if (is_numeric($this->input->get('status')) && $key == $this->input->get('status')):?> selected="selected"<?php endif;?>><?php echo $value;?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit">搜索</button>
                            <button class="btn reset_button_search" type="button">重置条件</button>
                        </div>
                    </form>
                </div>
            </div>
            
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>列表</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="dataTables_wrapper form-inline">
                        <div class="clearfix">
                            <a href="<?php echo base_url('advert/add') ?>" class="add-button-link">
                                <div class="btn-group">
                                    <button class="btn green"><i class="icon-plus"></i> 添加</button>
                                </div>
                            </a>
                        </div>
                        <?php if ($all_rows > 0) :?>
                        <table class="table table-striped table-bordered table-hover" id="sample_1">
                            <thead class="flip-content">
                                <tr>
                                    <th><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"></th>
                                    <th>编号</th>
                                    <th>标题</th>
                                    <th>供应商</th>
                                    <th>图片</th>
                                    <th>展示位置</th>
                                    <th>跳转类型</th>
                                    <th>打开参数</th>
                                    <th>排序</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($line_list->result() as $item) : ?>
                                <tr>
                                    <td width="15"><input type="checkbox" class="checkboxes" value="1" ></td>
                                    <td><?php echo $item->id;?></td>
                                    <td><?php echo $item->title;?></td>
                                    <td><?php echo $item->provider_id;?></td>
                                    <td>
                                		<div class="media">
                                			<div class="media-left">
                                                <a target="_blank" href="<?php echo $this->config->show_image_url($item->picture);?>">
                                                    <img class="media-object" style="max-height:120px;max-width:120px;" src="<?php echo $this->config->show_image_url($item->picture); ?>">
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                    <td><?php echo $advertArray[$item->position];?></td>
                                    <td><?php echo $item->opentype;?></td>
                                    <td><?php echo $item->openvar;?></td>
                                    <td><?php echo $item->sort;?></td>
                                    <td>
                                        <a href="javascript:;" class="modify-advert-flag glyphicons no-js <?php if ($item->status == 1):?>ok_2<?php else :?>remove_2<?php endif;?>" data-advert-id="<?php echo $item->id;?>" data-flag="<?php echo $item->status ?>">
                                            <i></i>
                                        </a>
                                    </td>
                                    <td width="145">
                                        <a class="btn mini green" href="<?php echo base_url('advert/edit/'.$item->id) ?>"><i class="icon-edit"></i> 编辑</a>
                                        <a class="btn mini green" href="<?php echo base_url('advert/delete/'.$item->id).'?picture='.$item->picture ?>" onclick="return confirm('确定要删除？')"><i class="icon-trash"></i> 删除</a>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            </tbody>
                        </table>
                        <div class="row-fluid">
                            <div class="span6">
                                <div class="dataTables_info">
                                    <span>当前第</span><span style="color: red"><?php echo $pg_now?></span>页 
                                    <span>共</span><span style="color: red"><?php echo $all_rows?></span>条数据
                                    <span>每页显示20条 </span>
                                    <?php echo $pg_link ?>
                                </div>
                            </div>
                        </div>
                        <?php else: ?>
                            <div class="alert"><p>未找到数据。<p></div>
                        <?php endif ?>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer');?>
<script type="text/javascript">
$(function(){
    $('.modify-advert-flag').click(function(){
        var status = '禁用';
        if ($(this).hasClass('remove_2')) {
            status = '启用';
        }
        if (confirm('确定要'+status+'?')) {
            var obj = $(this);
            var id = $(this).attr('data-advert-id');
            var status = $(this).attr('data-flag');
            $.ajax({
                url:hostUrl()+'/advert/toggle',
                type:'POST',
                dataType:'json',
                data: {id:id, status:status},
                success: function(data) {
                    if (data.status == 0) {
                        obj.attr('data-flag', data.status).addClass('remove_2').removeClass('ok_2');
                    } else if(data.status == 1) {
                        obj.attr('data-flag', data.status).addClass('ok_2').removeClass('remove_2');
                    } else {
                        alert('操作失败');
                    }
                }
            });
        }
    });
});
</script>